# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=ruby-minitest
_gemname=minitest
# Keep version in sync with "Bundled gems" (https://stdgems.org) for the
# packaged Ruby version.
pkgver=5.20.0
pkgrel=0
pkgdesc="Suite of testing facilities supporting TDD, BDD, mocking, and benchmarking for Ruby"
url="https://github.com/minitest/minitest"
arch="noarch"
license="MIT"
depends="ruby"
makedepends="ruby-rdoc"
checkdepends="ruby-rake"
subpackages="$pkgname-doc"
source="https://github.com/minitest/minitest/archive/v$pkgver/$_gemname-$pkgver.tar.gz
	https://rubygems.org/downloads/$_gemname-$pkgver.gem
	test-remove-hoe.patch
	"
builddir="$srcdir/$_gemname-$pkgver"
options="!check"  # circular dependency on ruby-rake

prepare() {
	default_prepare

	# Generate gemspec (there's no gemspec in the source).
	gem specification -l --ruby "$srcdir"/$_gemname-$pkgver.gem \
		> "$builddir"/$_gemname.gemspec
}

build() {
	gem build $_gemname.gemspec
}

check() {
	ruby -Ilib -Itest -e "Dir.glob('./test/**/test_*.rb', &method(:require))"
}

package() {
	local gemdir="$pkgdir/$(ruby -e 'puts Gem.default_dir')"
	local geminstdir="$gemdir/gems/$_gemname-$pkgver"

	gem install \
		--local \
		--install-dir "$gemdir" \
		--ignore-dependencies \
		--document ri \
		--verbose \
		$_gemname

	# Remove unnessecary files
	cd "$gemdir"
	rm -rf build_info cache extensions plugins

	cd "$geminstdir"
	rm -rf History.* Manifest.* README.* Rakefile test/
}

doc() {
	pkgdesc="$pkgdesc (ri docs)"

	amove "$(ruby -e 'puts Gem.default_dir')"/doc
}

sha512sums="
4872ad67a92c3065e821042165b2a1feafbd71ef4713e522fcc04293c8262d09d916947a73e1709560ccf2491a67a1badaf9a8626fddf1643a7a429d719b125d  minitest-5.20.0.tar.gz
906dba1226ed301ad0d7aae2fa138670101e87b11ced69e0c362e65d74fee58a5341756fed8be1f2900863e19c11adcae35ed6ebe7372bb93be0c131dae85a3c  minitest-5.20.0.gem
fdfc066799a351c1b237c2991501dc0c5e394c6066c873e8cc32941adc4ef956b5550fffae5d62a275917c82075264504dd1b457370703c2b870bfb28510f2ef  test-remove-hoe.patch
"
